package jannex.sql.extensions;

import jannex.Jannex;
import jannex.internal.ExceptionFactory;
import jannex.sql.JxSQLXML;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import java.sql.SQLException;
import java.sql.SQLXML;

public class SQLXMLImpl implements JxSQLXML {

    private final Jannex jannex;
    private final SQLXML sqlxml;

    public SQLXMLImpl(SQLXML sqlxml, Jannex jannex) {
        this.sqlxml = sqlxml;
        this.jannex = jannex;
    }

    @Override
    public void free() {
        try {
            sqlxml.free();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public InputStream getBinaryStream() {
        try {
            return sqlxml.getBinaryStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public OutputStream setBinaryStream() {
        try {
            return sqlxml.setBinaryStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public Reader getCharacterStream() {
        try {
            return sqlxml.getCharacterStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public Writer setCharacterStream() {
        try {
            return sqlxml.setCharacterStream();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public String getString() {
        try {
            return sqlxml.getString();
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public void setString(String value) {
        try {
            sqlxml.setString(value);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public <T extends Source> T getSource(Class<T> sourceClass) {
        try {
            return sqlxml.getSource(sourceClass);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }

    @Override
    public <T extends Result> T setResult(Class<T> resultClass) {
        try {
            return sqlxml.setResult(resultClass);
        } catch (SQLException e) {
            throw ExceptionFactory.make(e);
        }
    }
}
